package com.abner.basis.auxiliary;

import java.util.concurrent.CountDownLatch;

/**
 * JUC辅助类 CountDownLatch：使一个线程在等待另外一些线程完成各自工作之后，再继续执行
 *     班长需要等6位同学离开教室后进行锁门
 * @author yuhui
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println("第"+Thread.currentThread().getName()+"名离开教室");
                countDownLatch.countDown();
            },String.valueOf(i+1)).start();

        }

        countDownLatch.await();

        System.out.println("班长锁门了");
    }
}
